package com.tl.khadmin.controller;
 
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tl.khadmin.bean.ProductAttribute;
import com.tl.khadmin.bean.ProductType;
import com.tl.khadmin.bean.Staff;
import com.tl.khadmin.bean.dto.ProductListDto;
import com.tl.khadmin.page.Page;
import com.tl.khadmin.service.ProductAttributeIService;
import com.tl.khadmin.service.ProductTypeIService;
import com.tl.khadmin.util.CommonUtil;

/**
 * 商品属性数据控制器
 * @author 123
 */
@RestController
@RequestMapping(value = "/productattribute")
public class ProductAttributeController {
	
	@Resource
	private ProductAttributeIService productAttributeService; 
	
	/**
	 * @param param level：查询商品品牌列表
	 * @param param brandName：名称，模糊查询
	 * @param param status：1启用，2禁用
	 * @return
	 */
	@RequestMapping(value="/list") 
	public Map<String, List<ProductAttribute>> listProductAttribute(@RequestParam Map<String ,Object> param){
		return CommonUtil.returnResultCodeJson("list", productAttributeService.listProductAttribute(param));
	}

	@RequestMapping(value = "/showbypage")
	public Map<String, Page<ProductAttribute>> showProductAttributeByPage(@RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", productAttributeService.showProductAttributeByPage(pageNum, pageSize, params));
	}
	
	@RequestMapping(value = "/save")
	@ResponseBody
	public String saveProductAttribute(HttpSession session, @Valid ProductAttribute productAttribute, BindingResult br) {
		return productAttributeService.saveProductAttribute(session, productAttribute);
	}
	
	@RequestMapping(value = "/update")
	@ResponseBody
	public String updateProductAttribute( @Valid ProductAttribute productAttribute, BindingResult br) {
		return productAttributeService.updateProductAttribute(productAttribute);
	}

	@RequestMapping(value = "/deletebyids")
	@ResponseBody
	public String deleteByIds(String ids) {
		if(StringUtils.isBlank(ids)){
			return CommonUtil.returnMapResultByRows(0, "","未勾选");
		}
		return productAttributeService.deleteByIds(ids);
	}

	@RequestMapping(value = "/querybyid")
	@ResponseBody
	public Map<String, Object> queryProductAttributeById(Long id) {
		if(id==null){
			return null;
		}
		return productAttributeService.queryProductAttributeById(id);
	}
	
}
